1
เกินการค้นหาพื้นฐาน: การแก้ไขข้อจำกัดของความคล้ายคลึงเชิงความหมาย
AI010Lesson 8
00:00

เกินความคล้ายคลึง

ปัญหา "ปัญหา 80%"เกิดขึ้นเมื่อการค้นหาเชิงความหมายพื้นฐานทำงานได้ดีกับคำถามง่ายๆ แต่ล้มเหลวในกรณีเฉพาะที่ซับซ้อน เมื่อเราค้นหาโดยอาศัยความคล้ายคลึงเพียงอย่างเดียว คลังเวกเตอร์มักจะส่งกลับชิ้นส่วนที่มีค่าตัวเลขใกล้เคียงกันมากที่สุด อย่างไรก็ตาม หากชิ้นส่วนเหล่านั้นเหมือนกันเกือบทุกประการ โมเดลภาษาขนาดใหญ่ (LLM) จะได้รับข้อมูลซ้ำซ้อน ทำให้เสียพื้นที่หน่วยความจำที่จำกัด และพลาดมุมมองที่กว้างขึ้น

หลักการค้นหาขั้นสูง

  1. ความสำคัญสูงสุดตามขอบเขต (MMR):แทนที่จะเลือกชิ้นส่วนที่คล้ายกันที่สุดเพียงอย่างเดียว ระบบ MMR สร้างสมดุลระหว่างความเกี่ยวข้องและความหลากหลาย เพื่อหลีกเลี่ยงการซ้ำซ้อน
    $$MMR = \text{argmax}_{d \in R \setminus S} [\lambda \cdot \text{sim}(d, q) - (1 - \lambda) \cdot \max_{s \in S} \text{sim}(d, s)]$$
  2. การสอบถามตนเอง:ใช้โมเดลภาษาขนาดใหญ่ (LLM) แปลงภาษาธรรมชาติเป็นตัวกรองข้อมูลเมตาแบบโครงสร้าง (เช่น กรองตาม "ตอนที่ 3" หรือ "แหล่งที่มา: ไฟล์ PDF")
  3. การบีบอัดบริบท:หดขนาดเอกสารที่ค้นพบเพื่อแยกเฉพาะช่วงข้อมูลที่มีประโยชน์สูงและเกี่ยวข้องกับคำถาม เก็บจำนวนโทเคนไว้
กับดักของการซ้ำซ้อน
การให้โมเดลภาษาขนาดใหญ่ (LLM) สามฉบับของย่อหน้าเดียวกันไม่ได้ทำให้มันฉลาดขึ้น—มันแค่ทำให้คำสั่ง (prompt) มีต้นทุนสูงขึ้นเท่านั้น ความหลากหลายคือหัวใจของบริบทที่มีประโยชน์สูง
retrieval_advanced.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Knowledge Check
You want your system to answer "What did the instructor say about probability in the third lecture?" specifically. Which tool allows the LLM to automatically apply a filter for { "source": "lecture3.pdf" }?
ConversationBufferMemory
Self-Querying Retriever
Contextual Compression
MapReduce Chain
Challenge: The Token Limit Dilemma
Apply advanced retrieval strategies to solve a real-world constraint.
You are building a RAG system for a legal firm. The documents retrieved are 50 pages long, but only 2 sentences per page are actually relevant to the user's specific query. The standard "Stuff" chain is throwing an OutOfTokens error because the context window is overflowing with irrelevant text.
Step 1
Identify the core problem and select the appropriate advanced retrieval tool to solve it without losing specific nuances.
Problem: The context window limit is being exceeded by "low-nutrient" text surrounding the relevant facts.

Tool Selection:ContextualCompressionRetriever
Step 2
What specific component must you use in conjunction with this retriever to "squeeze" the documents?
Solution: Use an LLMChainExtractor as the base for your compressor. This will process the retrieved documents and extract only the snippets relevant to the query, passing a much smaller, highly concentrated context to the final prompt.